import { defineStore } from "pinia";
// pinia 仓库写法：组合式API、选择式API
import { HospitalDetail,HospitalDepartment } from "@/api/hospitaldetails/index";
// 引入详情数据的ts类型
import type {HospitalDetailRes,HospitalDetailData,HospitalDepartmentRes,HospitalDepartmentArr} from '@/api/hospitaldetails/type'
const useDetailStore = defineStore("Detail", {
  // 拿数据->取数据->存数据
  state: () => {
    return {
      // 医院详情的数据
      hospitalInfo: {} as HospitalDetailData,
      // 存储医院科室的数据
      HospitalDepartmentInfo:{} as HospitalDepartmentArr
    };
  },
  actions: {
    // 获取医院详情的方法
    async getHospital(hoscode: string) {
      let result: HospitalDetailRes = await HospitalDetail(hoscode);
      if (result.code == 200) {
        this.hospitalInfo = result.data;
      }
    },
    // 获取医院科室的方法
    async getDepartment(hoscode: string) {
      let result: HospitalDepartmentRes = await HospitalDepartment(hoscode);
      if (result.code == 200) {
        this.HospitalDepartmentInfo = result.data;
      }
    }
  },
  getters: {},
});
// 获取仓库的方法对外暴露
export default useDetailStore;